package com.lin.controller.user;

import com.lin.common.result.Result;
import com.lin.entity.CollectionEntity;
import com.lin.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/clt")
@Api(tags = "收藏夹相关接口")
@Slf4j
public class CollectionController {


    @Autowired
    private CollectionService collectionService;
    /**
     * 获取收藏夹
     * @return
     */
    @GetMapping
    @ApiOperation("获取收藏夹")
    public Result<CollectionEntity> getCollection(@RequestBody Integer userId){
        log.info("获取用户收藏夹：{}",userId);
        CollectionEntity collection = collectionService.getCollection(userId);
        return Result.success(collection);
    }

    /**
     * 新建收藏夹
     * @param collection
     * @return
     */
    @PostMapping
    @ApiOperation("新建收藏夹")
    public Result<CollectionEntity> saveClt(@RequestBody CollectionEntity collection){
        log.info("新建收藏夹：{}",collection);
        collection.setCltTime(LocalDateTime.now());
        collectionService.saveClt(collection);
        return Result.success(collection);
    }

    /**
     * 更新收藏夹
     * @param collection
     * @return
     */
    @PutMapping
    @ApiOperation("更新收藏夹")
    public Result<CollectionEntity> updateClt(@RequestBody CollectionEntity collection){
        log.info("更新收藏夹：{}",collection);
        collectionService.updateClt(collection);
        return Result.success(collection);
    }

    /**
     * 删除收藏夹
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除收藏夹")
    public Result deleteClt(@RequestBody Integer id){
        log.info("删除收藏夹：{}",id);
        collectionService.deleteClt(id);
        return Result.success();
    }
    /**
     * 获取收藏夹里的内容
     * @param cltId
     * @return
     * TODO 获取收藏夹里的内容
     */
    @GetMapping("/sto")
    @ApiOperation("获取收藏夹里的内容")
    public Result getCltSto(@RequestBody Integer cltId){
        return Result.success();
    }
}
